/*
给定一个不含重复数字的数组 nums ，返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。

输入：nums = [1,2,3]
输出：[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
*/
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    vector<vector<int>> permute(vector<int>& nums) {
        vector<vector<int> > res;
        back(res, nums, 0, (int)nums.size());
        return res;
    }
	
	void back(vector<vector<int>> & res, vector<int> & nums, int index, int len){
		if(index == len){
			res.push_back(nums);
			return;
		}
		for(int i = index; i < len; i++){
			swap(nums[i], nums[index]);
			back(res, nums, index+1, len);
			swap(nums[index], nums[i]);
		}
	}
};

int main(){
	vector<int> a = {1,2,3};
	Solution so;
	auto res = so.permute(a);
	
	for(auto items : res){
		for(auto item : items){
			cout << item << ",";
		}
		cout << endl;
	}
	
	return 0;
}